package com.iamteer.c_type;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

public class MyConverter extends StrutsTypeConverter {

	// yyyyMMdd yyyy-MM-dd yyyy年MM月dd日
	DateFormat[] df = {new SimpleDateFormat("yyyyMMdd"),
						new SimpleDateFormat("yyyy-MM-dd"),
						new SimpleDateFormat("yyyy年MM月dd日")};
	@Override
	public Object convertFromString(Map contex, String[] values, Class toClass) {
		if (values == null || values.length == 0) {
			return null;
		}
		if (Date.class != toClass) {
			return null;
		}
		// 转换

		for (int i = 0; i < df.length; i++) {
			try {
				return df[i].parse(values[0]);
			} catch (Exception e) {
				continue;
			}
		}
		return null;
	}
	@Override
	public String convertToString(Map arg0, Object arg1) {
		// TODO Auto-generated method stub
		return null;
	}

}
